package com.itheima.leyou.service;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.logging.Logger;

@Service
public class ClientService {

    private static final String STORAGE_QUEUE = "storage_queue";
    private static final String ORDER_QUEUE = "order_queue";
    private static final String ORDER_STATUS_QUEUE = "order_status_queue";

    private Logger logger = Logger.getLogger(String.valueOf(ClientService.class));

    @Autowired
    private AmqpTemplate amqpTemplate;

    //type: 0-库存队列；1-订单队列；2-更新订单状态
    public String test(int type, int count, String content){
        for (int i=1; i<=count; i++){

            if (type==0){
                amqpTemplate.convertAndSend(STORAGE_QUEUE, content); //"1_27359021557_1_0"
                logger.info("发送消息："+STORAGE_QUEUE+"："+content);
            }

            if (type==1){
                amqpTemplate.convertAndSend(ORDER_QUEUE, content);  //order_id:
                logger.info("发送消息："+ORDER_QUEUE+"："+content);
            }

            if (type==2){
                amqpTemplate.convertAndSend(ORDER_STATUS_QUEUE, content);  //order_id
                logger.info("发送消息："+ORDER_STATUS_QUEUE+"："+content);
            }
        }
        return "队列消息发送完成：type="+type+"；count="+count+"；content="+content;
    }
}
